<!--
 * @Author: your name
 * @Date: 2019-11-09 19:50:51
 * @LastEditTime: 2019-11-10 10:48:55
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \leetcode\text.html
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
    <script>
        // var fourSum = function(nums, target) {
        //     let arr = [];
        //     if (nums.length < 4) {
        //         return arr;
        //     }
        //     for (let i = 0; i < nums.length - 3; i++) {
        //         for (let j = i + 1; j < nums.length - 2; j++) {
        //             for (let k = j + 1; k < nums.length - 1; k++) {
        //                 for (let l = k + 1; l < nums.length; l++) {
        //                     if (nums[i] + nums[j] + nums[k] + nums[l] == target) {
        //                         arr.push([nums[i], nums[j], nums[k], nums[l]]);
        //                     }
        //                 }
        //             }
        //         }
        //     }
        //     if (arr.length > 0) {
        //         let res = {}
        //         arr.forEach(item => {
        //             item.sort((a, b) => a - b);
        //             res[item] = item;
        //         });
        //         return Object.values(res)
        //     } else {
        //         return arr;
        //     }
        // };

        // console.log(fourSum([-3, -2, -1, 0, 0, 1, 2, 3], 0));





        var divide = function(dividend, divisor) {
            if (dividend == 0) {
                return 0;
            }
            let flag = (dividend > 0) ^ (divisor > 0);
            let result = 0;
            if (dividend > 0) {
                dividend = -dividend;
            }
            if (divisor > 0) {
                divisor = -divisor;
            }
            while (dividend <= divisor) {
                let temp_result = -1;
                let temp_divisor = divisor;
                while (dividend <= (temp_divisor << 1)) {
                    if (temp_divisor <= (Math.pow(-2, 31) >> 1)) {
                        break;
                    }
                    temp_result = temp_result << 1;
                    temp_divisor = temp_divisor << 1;
                }
                dividend = dividend - temp_divisor;
                result += temp_result;
            }
            if (!flag) {
                if (result <= Math.pow(-2, 31)) {
                    return Math.pow(2, 31) - 1;
                }
                result = -result;
            }
            return result;

        };

        console.log(divide(-2147483648, 1));
    </script>
</body>

</html>